package com.ljw.security.springmvc.init;

import com.ljw.security.springmvc.config.ApplicationConfig;
import com.ljw.security.springmvc.config.WebConfig;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;


/**
 * @FileName 自定义类SpringApplicationInitializer 实现于WebApplicationInitializer接口
 *          ，Spring容器启动时加载WebApplicationInitializer接口的所有实现类。
 * @Description TODO  SpringApplicationInitializer 相当于web.xml，使用了servlet3.0开发则不需要再定义web.xml，
 * @Author ljw
 * @Date 2020/8/31 12:34
 * @Version 1.0
 */
public class SpringApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        //相当于web.xml 加载 application‐context.xml
        return new Class[]{ApplicationConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        //相当于web.xml 加载 springMvc.xml
        return new Class[]{WebConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        //相当于web.xml中的<url‐pattern>/</url‐pattern>，controller层对应的根请求路径
        //将DispatcherServlet映射到 "/" ,即拦截所有请求交给DispatcherServlet处理
        return new String[]{"/"};
    }




    /*
    <web‐app>
        <listener>
            <listener‐class>org.springframework.web.context.ContextLoaderListener</listener‐class>
        </listener>
        <context‐param>
            <param‐name>contextConfigLocation</param‐name>
            <param‐value>/WEB‐INF/application‐context.xml</param‐value>
        </context‐param>
        <servlet>
            <servlet‐name>springmvc</servlet‐name>
            <servlet‐class>org.springframework.web.servlet.DispatcherServlet</servlet‐class>
            <init‐param>
                <param‐name>contextConfigLocation</param‐name>
                <param‐value>/WEB‐INF/spring‐mvc.xml</param‐value>
            </init‐param>
            <load‐on‐startup>1</load‐on‐startup>
        </servlet>
        <servlet‐mapping>
            <servlet‐name>springmvc</servlet‐name>
            <url‐pattern>/</url‐pattern>
        </servlet‐mapping>
    </web‐app>
    */
}
